<template lang="html">
  <div class="container" v-loading="loading">
      <div class="search">
          <el-form :inline="true" class="demo-form-inline">
              <el-form-item>
                <el-input class="form_input" v-model="searchText" placeholder=""></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" :disabled="loading" size="small" @click="onSubmit">搜索</el-button>
              </el-form-item>
              <el-form-item>
                <datePicker startEndTime @onFilter="onFilter" />
              </el-form-item>
              <el-form-item>
                <span>统计时间：{{statisTime}}</span>
              </el-form-item>
          </el-form>



          <div class="export_excl">
            <el-button size="small" @click="exportExcl" type="primary">导出<i class="el-icon-upload el-icon--right"></i></el-button>
          </div>
      </div>

      <div class="tables">
          <div class="designer_list">
              <ul>
                  <li v-for="(item,index) in ranks" :key="index">
                      <div class="mask_detail" @click="handleDetail(item.id)">查看详情></div>
                      <div class="r_no">
                        <span>NO.{{index+1}}</span>
                        <i class="el-icon-arrow-right"></i>
                      </div>
                      <div class="designer_info">
                        <div class="avatar"><img :src="item.headImg" alt=""></div>
                        <div class="name">{{item.realName}}</div>
                        <div class="phone">{{item.phone}}</div>
                      </div>
                      <div class="maintain_info">
                        <div class="text">
                          <p class="n">{{item.repairCount}}</p>
                          <p>维修数量</p>
                        </div>
                        <div class="text">
                          <p class="n">￥{{item.sumReceiptsPrice||0}}</p>
                          <p>维修费用</p>
                        </div>
                      </div>
                  </li>
              </ul>
          </div>
      </div>

  </div>
</template>

<script>
export default {
  data(){
    return {
      loading: false,
      searchText: '',
      statisTime: '',
      date: [],
      year: '',
      month: '',
      day: '',
      ranks: []
    }
  },
  created(){
    this.getServeData();
  },
  methods: {
    getServeData(){
      this.loading = true;
      this.$http.selectDataStatsDesignerCountPage({
        query: this.searchText,
        startTime: (this.date&&this.date[0]) || '',
        endTime: (this.date&&this.date[1]) || '',
        dayTime: this.day,
        monthTime: this.month,
        yearTime: this.year,
      }).then(res=>{
        this.loading = false;
        if(res.data.code == 0){
          this.ranks = res.data.data;
        }
      })
    },
    onFilter(e){
      this.statisTime = e.val;
      this.date = [];
      this.year = '';
      this.month = '';
      this.day = '';
      switch (e.key) {
        case 1: this.day = e.val; break;
        case 2: this.month = e.val; break;
        case 3: this.year = e.val; break;
        case 4: 
            this.date = [...e.val];
            if(e.val[0]) this.statisTime = `${e.val[0]} - ${e.val[1]}`;
            else this.statisTime = '';
         break;
      }
      this.onSubmit()
    },

    exportsAPI(){
      ids && (
        this.$http.selectDataStatsDesignerCountExport({
          query: this.searchText,
          startTime: (this.date&&this.date[0]) || '',
          endTime: (this.date&&this.date[1]) || '',
          dayTime: this.day,
          monthTime: this.month,
          yearTime: this.year,
        })
      );
    },
    handleDetail(id){
      window.sessionStorage.setItem("maintain_designer", id);
      this.$router.push({path: '/statistics/maintain_statistics/maintain_designer'});
    },

    onSubmit(){
      this.getServeData();
    },
    exportExcl(){
      this.$confirm('确定要导出吗？').then(()=>{
        this.exportsAPI();
      }).catch(e=>0);
    }
  }
}
</script>

<style lang="css" scoped>
.container{
  background: none
}
.active{
  color: #FFF;
  background-color: #409EFF;
  border-color: #409EFF;
}
.search{
  display: flex;
  position: relative;
}
.export_excl{
  position: absolute;
  right: 0
}
.designer_list ul{
  display: flex;
  flex-wrap: wrap;
}
.designer_list li{
  width: 216px;
  overflow: hidden;
  border-radius: 4px;
  box-shadow:0px 1px 4px 0px rgba(0, 0, 0, 0.08);
  background: #fff;
  position: relative;
  cursor: pointer;
  margin-bottom: 16px;
  margin-right: 16px;
}
.designer_list .mask_detail{
  position: absolute;
  left: 0;
  top: -100%;
  z-index: 9;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.4);
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all ease 0.2s;
}
.designer_list li:hover .mask_detail{
  top: 0;
}
.designer_list .r_no{
  padding: 16px;
  display: flex;
  justify-content: space-between;
}
.designer_list .r_no span{
  font-size: 14px;
  color: #999;
}
.designer_list .r_no i{
  color: #6F6C6F;
}
.designer_list .designer_info{
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  text-align: center;
  justify-content: center;
  padding-bottom: 20px;
  border-bottom: 1px solid #E8E8E8;
}
.designer_info .avatar{
  width: 50px;
  height: 50px;
  border-radius: 50%;
  overflow: hidden;
  background: #f8f8f8
}
.designer_info .avatar img{
  display: block;
  width: 100%;
}
.designer_info .name{
  font-size: 16px;
  width: 100%;
  color: #333;
  font-weight: 600;
  line-height: 30px;
}
.designer_info .phone{
  font-size: 14px;
  width: 100%;
  color: #999;
}
.maintain_info {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
.maintain_info .text{
  width: 50%;
  text-align: center;
  box-sizing: border-box;
  padding: 16px 0;
  border-right: 1px solid #E8E8E8;
}
.maintain_info .text:last-child{
  border-right: 0;
}
.maintain_info .text p{
  font-size: 14px;
  color: #999;
}
.maintain_info .text .n{
  font-size: 18px;
  line-height: 30px;
  color: #333;
}
</style>
